package com.qys.erp.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.qys.erp.domain.DeliveryLog;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.qys.erp.domain.Delivery;
import com.qys.erp.service.IDeliveryService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品出库Controller
 * 
 * @author qys
 * @date 2021-08-22
 */
@RestController
@RequestMapping("/erp/delivery")
public class DeliveryController extends BaseController
{
    @Autowired
    private IDeliveryService deliveryService;

    /**
     * 查询产品入库列表
     */
    @PreAuthorize("@ss.hasPermi('erp:delivery:list')")
    @GetMapping("/list")
    public TableDataInfo list(Delivery delivery)
    {
        startPage();
        List<Delivery> list = deliveryService.selectDeliveryList(delivery);
        return getDataTable(list);
    }

    /**
     * 查询产品出库列表
     */
    @PreAuthorize("@ss.hasPermi('erp:delivery:list')")
    @GetMapping("/listout")
    public TableDataInfo listout(Delivery delivery)
    {
        startPage();
        List<Delivery> listout = deliveryService.outselectDeliveryList(delivery);

        return getDataTable(listout);
    }

    /**
     * 导出产品出库列表
     */
    @PreAuthorize("@ss.hasPermi('erp:delivery:export')")
    @Log(title = "产品出库", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Delivery delivery)
    {
        List<Delivery> list = deliveryService.selectDeliveryList(delivery);
        ExcelUtil<Delivery> util = new ExcelUtil<Delivery>(Delivery.class);
        return util.exportExcel(list, "产品出库数据");
    }

    /**
     * 获取产品出库详细信息
     */
   /* @PreAuthorize("@ss.hasPermi('erp:delivery:query')")
    @GetMapping(value = "/out/{delId}")
    public AjaxResult getoutInfo(@PathVariable("delId") Long delId)
    {
        System.out.println("1231231313"+ deliveryService.outselectDeliveryById(delId));
        return AjaxResult.success(deliveryService.outselectDeliveryById(delId));
    }*/

    /**
     * 获取产品入库详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:delivery:query')")
    @GetMapping(value = "/{delId}")
    public AjaxResult getInfo(@PathVariable("delId") Long delId)
    {
        return AjaxResult.success(deliveryService.selectDeliveryById(delId));
    }

    /**
     * 新增产品出库
     */
    @PreAuthorize("@ss.hasPermi('erp:delivery:add')")
    @Log(title = "产品出库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Delivery delivery)
    {

        return toAjax(deliveryService.insertDelivery(delivery));
    }

    /**
     * 修改产品出库
     */
    @PreAuthorize("@ss.hasPermi('erp:delivery:edit')")
    @Log(title = "产品出库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Delivery delivery)
    {
        return toAjax(deliveryService.updateDelivery(delivery));
    }

    /**
     * 删除产品出库
     */
    @PreAuthorize("@ss.hasPermi('erp:delivery:remove')")
    @Log(title = "产品出库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{delIds}")
    public AjaxResult remove(@PathVariable Long[] delIds)
    {
        return toAjax(deliveryService.deleteDeliveryByIds(delIds));
    }
}
